<?
/**
 * VoiceOne Settings/IVR/
 *
 * Frontend to provide access to the ivr system in voiceone.
 * @package voiceone
 * @subpackage  settings_ivr
 */
  include ("../../admin/config/cfg.php");
  global $cwlang;
 	sajax_init();

  //=================== GET ====================
  $alert=getAlert();
  // Delete ivr
  if(($_GET["cmd"]=="del")&&($_GET["id"]!="")){
    $ret=$asterisk->delIvrNode($_GET["id"]);
    if ($ret>0) $alert="<div class=\"AlertGood\">".T_("The IVR has been deleted")."</div>";
    else $alert="<div class=\"AlertBad\">".T_("The IVR hasn't deleted")."</div>";
    goToMainPage($alert,"./");
  }

  //================ PAGE LOGIC ================
  //get the IVR list
  $ivr=$asterisk->getIvr(0);
  if(is_array($ivr)){
    foreach($ivr as $i) {
      $id=$i["id"];
      $name=$i["name"];
      $html.="<td><img src=\"$relBasePath/public/img/ivr.gif\" /> <a href=\"edit/?ivr=$id\">$name</a> <a href=\"$PHP_SELF?cmd=del&id=$id\" onclick=\"if (confirm('".sprintf(T_("Are you sure to delete IVR %1\$s ?"),$name )."')) return true; else return false;\"><img src=\"$relBasePath/public/img/trash.gif\" /></a></td>\n";
      if((++$count)%2==0) $html.="</tr><tr>\n";
    }
  }

  //================ MAIN CONTENTS ================
  ob_start();
  ?>
    <div class="SectionHeader">
      <?=$alert?>
      <h1><?=T_("IVR")?></h1> 
      <h3><a href="./edit/" class="admin" ><?=T_("New IVR")?></a></h3>
    </div>
    <table class="todolist">
      <tr>
        <?=$html?>
      </tr>
    </table>
  <?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start(); 
  ?>
    <div class="Sidebar">
      <!-- Description -->
      <h1><?=T_("Informations")?></h1>
      <p><?=T_("&nbsp;")?></p>
    </div>
  <?  
  $sidebar=ob_get_contents();
  ob_end_clean();

  //================ SETTINGS ================
  $smarty->assign("section", "ivr");
  $smarty->assign("subsection", "");
  $smarty->assign("templateType", "TwoColLeft");  //OneCol, TwoColLeft, TwoColRight
  $smarty->assign("contents", $contents);
  $smarty->assign("sidebar", $sidebar);
  $smarty->assign("ajax", $js);
  $smarty->display('settings.tpl');
?>

